package com.centaline.androidsalesblog.adapter;

import android.content.Context;
import android.view.View;

import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.adapter.viewholder.SearchVH;
import com.centaline.androidsalesblog.iml.RecyclerViewItemOnClickListener;
import com.centaline.androidsalesblog.model.businissobject.SearchDistanceBo;
import com.centanet.framework.base.BaseAdapter1;

import java.util.ArrayList;

/**
 * 搜索
 * Created by Lihq on 16/3/9.
 */
public class SearchDistanceAdapter extends BaseAdapter1<SearchVH> {

    private final ArrayList<SearchDistanceBo> list;
    private final RecyclerViewItemOnClickListener<SearchDistanceBo> itemOnClickListener;

    public SearchDistanceAdapter(Context context, ArrayList<SearchDistanceBo> list, RecyclerViewItemOnClickListener<SearchDistanceBo> itemOnClickListener) {
        super(context);
        this.list = list;
        this.itemOnClickListener = itemOnClickListener;
    }

    @Override
    protected int inflateByLayoutId() {
        return R.layout.item_search;
    }

    @Override
    protected SearchVH viewHolder(View view) {
        return new SearchVH(view);
    }

    @Override
    public void onBindViewHolder(SearchVH holder, int position) {
        final SearchDistanceBo searchDistanceBo = list.get(position);
        holder.atv_title.setText(searchDistanceBo.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnClickListener.onItemOnClick(searchDistanceBo, 0);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
